package cn.manyufun.myf.ui.main.model;


import org.json.JSONException;
import org.json.JSONObject;

import cn.manyufun.myf.api.Api;
import cn.manyufun.myf.api.HostType;
import cn.manyufun.myf.bean.ComicsListBean;
import cn.manyufun.myf.common.baserx.RxSchedulers;
import cn.manyufun.myf.common.commonutils.APIUtils;
import cn.manyufun.myf.common.commonutils.DisplayUtil;
import cn.manyufun.myf.ui.comics.contract.ComicsListContract;
import okhttp3.MediaType;
import okhttp3.RequestBody;
import rx.Observable;

/**
 * @author Kevin Xiao
 * @date Create Date: 2017-12-26
 * @Description
 */
public class ComicsListModel implements ComicsListContract.Model {
    @Override
    public Observable<ComicsListBean> getComicsListData() {
        JSONObject root = new JSONObject();
        JSONObject head = APIUtils.getHeadParamter();
        try {
            root.put("Head", head);
            root.put("RecommendImageSize", DisplayUtil.dip2px(216.7f) + "*" + DisplayUtil.dip2px(93.7f));
            root.put("HotListImageSize", DisplayUtil.dip2px(92f) + "*" + DisplayUtil.dip2px(127f));
            root.put("RankListImageSize", DisplayUtil.dip2px(100f) + "*" + DisplayUtil.dip2px(120f));
        } catch (JSONException e) {
            e.printStackTrace();
        }

        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"),root.toString());
        return Api.getDefault(HostType.manyufun).getNewsRecommend(requestBody)
                .compose(RxSchedulers.<ComicsListBean>io_main());
    }
}
